package com.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author FatterShadystart
 * @create 2023-01-18 16:38
 */
public class DateUtils {


    /**
     * String：yyyy-MM-dd HH:mm:ss    -> Date:yyyy-MM-dd HH:mm:ss
     * @param dateStr
     * @return
     */
    public static Date string2Date(String dateStr) throws ParseException {
        Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateStr);
        return date;
    }

    /**
     * 将时区转为yyyy-MM-dd HH:mm:ss
     * @param date
     * @return
     */
    public static String timeZone2YMdHms(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String returnTime = sdf.format(date);
        return returnTime;
    }



    /**
     * 将时间戳转为yyyy-MM-dd HH:mm:ss
     * @param timeStamp
     * @return
     */
    public static String timeStamp2YMdHms(String timeStamp) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String returnTime = sdf.format(new Date(Long.parseLong(timeStamp)));
        return returnTime;
    }


    /**
     * 获取当前时间戳
     * @return
     */
    public static String getNowTimeStamp() {
        return String.valueOf(System.currentTimeMillis());
    }







}
